/**
 * Class: BlinkingSphere
 *
 * Purpose: 
 *
 * Created: Jan 27, 2010 @ 9:36:50 AM
 * @author Ken Scott
 */
package org.openfantasia.ps.shape;

import org.openfantasia.ps.particle.Particle;
import org.openfantasia.ps.shape.BlinkingDot;
import org.openfantasia.ui.PColor;
import org.openfantasia.ui.PFrame;
import org.openfantasia.util.math.DPoint3;

public class BlinkingSphere extends BlinkingDot {

	private float radius = 10;


	public BlinkingSphere(PFrame frame) {
		super(frame);
	}


	public BlinkingSphere(PFrame frame, float weight, long period, float radius) {
		super(frame, weight, period);
		this.radius = radius;
	}


	public BlinkingSphere(PFrame frame, long period, float radius) {
		super(frame, period);
		this.radius = radius;
	}


	public void draw(Particle particle) {
		boolean on = ((System.currentTimeMillis() / period) & 1) == 1;
		PColor color = on ? particle.getFillColor() : PColor.INVISIBLE;
		PColor scaledColor = color.scale((float) particle.getBrightness());
		PColor solidifiedColor = scaledColor.opacify((float) particle.getOpacity());
		frame.fill(solidifiedColor);
		frame.stroke(solidifiedColor);
		DPoint3 pt = particle.getPosition();
		frame.translate((float) pt.p[0], (float) pt.p[1], (float) pt.p[2]);
		frame.sphere(radius);
		frame.translate((float) -pt.p[0], (float) -pt.p[1], (float) -pt.p[2]);
	}
}
